﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Library;
using BusinessLayer;

public partial class Administrator_MemberEdit : System.Web.UI.Page
{
    string cmd = "";
    int id = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        cmd = Request.QueryString["cmd"].ToString();
        switch (cmd)
        {
            case "edit":
                txtEmail.Enabled = true;
                rbStatus.Enabled = true;
                txtTel.Enabled = true;
                txtTen.Enabled = true;
                txtAddress.Enabled = true;
                btnUpdate.Enabled = true;
                id = Convert.ToInt32(Request.QueryString["Id"].ToString());
                if (!IsPostBack)
                {
                    FillData(BusinessLayer.Member.GetOne(id));
                }
                break;
        }
    }
    protected void FillData(Member member)
    {
        txtEmail.Text = member.Member_Email;
        txtTen.Text = member.Member_Name;
        txtTel.Text = member.Member_Tel;
        txtAddress.Text = member.Member_Address;
        rbStatus.Items.FindByValue(member.Status.ToString()).Selected = true;
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Member member = new Member();
        member.Member_ID = id;
        member.Member_Email = txtEmail.Text;
        member.Member_Address = txtAddress.Text;
        member.Member_Name = txtTen.Text;
        member.Status = Convert.ToInt32(rbStatus.SelectedValue);
        try
        {
            Member.Update(member);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void BbtnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("MemberManager.aspx");
    }
}